﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThoughtWorks.QRCode.Codec;

namespace YTCMS.Core.File
{
    /// <summary>
    /// 扫描二维码
    /// </summary>
    public class ScanImage
    {
        public enum S_ENCODE_MODE
        {
            ALPHA_NUMERIC = 0,
            NUMERIC = 1,
            BYTE = 2,
        }

        public enum S_ERROR_CORRECTION
        {
            L = 0,
            M = 1,
            Q = 2,
            H = 3,
        }
        public static Bitmap CreateImge(string data, int QRCodeScale = 4, int QRCodeVersion = 7, S_ERROR_CORRECTION QRCodeEncoder = S_ERROR_CORRECTION.M, S_ENCODE_MODE model = S_ENCODE_MODE.BYTE)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                throw new Exception("Data must not be empty.");
            }
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = (QRCodeEncoder.ENCODE_MODE)((int)model);
            qrCodeEncoder.QRCodeScale = QRCodeScale;
            qrCodeEncoder.QRCodeVersion = QRCodeVersion;
            qrCodeEncoder.QRCodeErrorCorrect = (QRCodeEncoder.ERROR_CORRECTION)((int)QRCodeEncoder);

            return qrCodeEncoder.Encode(data);
        }
    }
}
